package converters;

import java.util.Iterator;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import modelo.Servicioadicionalxsalon;
import modelo.ServicioadicionalxsalonId;
import services.ServicioAdicionalXSalonService;

@FacesConverter("servicioAdicionalXSalonConverter")
public class ServicioAdicionalXSalonConverter implements Converter {
	
	public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
        if(value != null && value.trim().length() > 0) {
        	ServicioAdicionalXSalonService service = (ServicioAdicionalXSalonService) fc.getExternalContext().getApplicationMap().get("servicioAdicionalXSalonService");
            Iterator<Servicioadicionalxsalon> i=service.getListaservicioadicionalxsalon().iterator();
            while (i.hasNext()) {
            	Servicioadicionalxsalon saxs = (Servicioadicionalxsalon) i.next();
				if(saxs.getId().getIdServicioAdicional() == Integer.parseInt(value))//ver despues
					return saxs;
								
			}
            return null;
        }
        else {
            return null;
        }
    }
 
	public String getAsString(FacesContext fc, UIComponent uic, Object object) {
        if(object != null) {
        	return String.valueOf(((Servicioadicionalxsalon) object).getId().getIdServicioAdicional());
        }
        else {
            return null;
        }
    }  

}